PUBLIC = ../../public
SRC = src
BIN = ../../bin
CFLAGS = -Wall -pedantic -ansi -Werror
CC = gcc
LIB_TOOL = ar
LIB_FLAGS = -r -s
COMPILE_FLAG = -c

all: release 

debug: CFLAGS+=-g 
debug: BIN=../../bin/debug
debug: $(BIN)/libSharedMemory.a clean
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		 LIBRARY CREATED			*"
	@echo "*							*"
	@echo "**********************************************************"

release: CFLAGS+=-g -DNDEBUG
release: BIN=../../bin/release
release: $(BIN)/libSharedMemory.a clean
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		 LIBRARY CREATED			*"
	@echo "*							*"
	@echo "**********************************************************"

$(BIN)/libSharedMemory.a: SharedMemory.o 
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		CREATING LIBRARY			*"
	@echo "*							*"
	@echo "**********************************************************"
	$(LIB_TOOL) $(LIB_FLAGS) $(BIN)/libSharedMemory.a SharedMemory.o 

Testdebug: CFLAGS+=-g -DSM_UTEST
Testdebug: BIN=bin/debug
Testdebug: $(BIN)/SharedMemoryTest clean
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		SUCCEFULY FINISHED			*"
	@echo "*							*"
	@echo "**********************************************************"


Testrelease: CFLAGS+=-DNDEBUG -DSM_UTEST
Testrelease: BIN=bin/release
Testrelease: $(BIN)/SharedMemoryTest clean
	@echo "**********************************************************"
	@echo "*							*"
	@echo "*		SUCCEFULY FINISHED			*"
	@echo "*							*"
	@echo "**********************************************************"

$(BIN)/SharedMemoryTest: SharedMemory.o
	$(CC) $(CFLAGS) SharedMemory.o -lrt -lpthread -o $(BIN)/SharedMemoryTest


SharedMemory.o: $(PUBLIC)/SharedMemory.h SharedMemory.c
	$(CC) $(COMPILE_FLAG) $(CFLAGS) -std=gnu99 -D_GNU_SOURCE -I$(PUBLIC) SharedMemory.c -o SharedMemory.o



clean: 
	rm *.o
